package com.zk.yygh.hosp.controller;

import com.zk.yygh.hosp.result.Result;
import com.zk.yygh.hosp.service.HospitalService;
import com.zk.yygh.hosp.service.ScheduleService;
import com.zk.yygh.model.hosp.Hospital;
import com.zk.yygh.model.hosp.Schedule;
import com.zk.yygh.model.user.Patient;
import com.zk.yygh.vo.hosp.HospitalQueryVo;
import com.zk.yygh.vo.hosp.ScheduleOrderVo;
import com.zk.yygh.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;


/**
 * @author: 张凯
 * @date: 2022/6/6 - 18:24
 */
@Api("医院管理")
@RestController
@RequestMapping("/admin/hosp/hospitalSet")
//@CrossOrigin
public class HospitalController {

    @Autowired
    HospitalService hospitalService;

    @Autowired
    private ScheduleService scheduleService;

    /**
     *
     * @param page：第几页
     * @param limit：该页显示记录数
     * @param hospitalQueryVo：查询的vo类
     * @return  查询的分页记录
     */
    @ApiOperation("获取分页列表")
    @GetMapping("selectPage/{page}/{limit}")
    public Result selectPage(@PathVariable("page") Integer page,
                             @PathVariable("limit") Integer limit,
                             HospitalQueryVo hospitalQueryVo){
        //调用业务层执行分页查询
        Page<Hospital> pages = hospitalService.selectPage(page, limit, hospitalQueryVo);
        return Result.ok(pages);
    }

    @ApiOperation(value = "2.更新医院上线状态")
    @PutMapping("update/{id}/{status}")
    public Result updateStatus(@PathVariable("id") String id,@PathVariable("status") Integer status){
        hospitalService.updateStatus(id,status);
        return Result.ok();
    }

    @ApiOperation(value ="3.根据id显示医院详情")
    @GetMapping("show/{id}")
    public Result showHospitalById(@PathVariable("id") String id){
        HashMap<String, Object> result = hospitalService.getHospitalById(id);
        return Result.ok(result);
    }

    @ApiOperation(value = "4.根据医院名称进行模糊查询")
    @GetMapping("findHospitalByName/{name}")
    public Result findHospitalByName(@PathVariable("name") String name){
        List<Hospital> hospitalList=hospitalService.findHospitalByName(name);
        return Result.ok(hospitalList);
    }

    @ApiOperation(value = "5.获取可预约排班分页数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode) {
        return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));
    }

    @ApiOperation(value = "6.获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode,
            @ApiParam(name = "workDate", value = "排班日期", required = true)
            @PathVariable String workDate) {
        return Result.ok(scheduleService.getDetailSchedule(hoscode, depcode, workDate));
    }

    @ApiOperation(value = "7.根据排班id获取排班数据")
    @GetMapping("getSchedule/{id}")
    public Result getSchedule(@PathVariable("id") String id){
//        System.out.println("---------->"+id);
        Schedule schedule = scheduleService.getScheduleById(id);
        return Result.ok(schedule);
    }

    @ApiOperation(value = "8.根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable("scheduleId") String scheduleId){
        return scheduleService.getScheduleOrderVo(scheduleId);
    }
}
